import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from "path"
// import Inspect from 'vite-plugin-inspect'

export default defineConfig(({mode}) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      react(), 
      // Inspect({
      //   build: true,
      //   outputDir: '.vite-inspect'
      // })
    ],
    server: {
      open: true,
      proxy: {
        '/mylearnblog/api': {
          target: env.VITE_PROXY_API_URL,
          changeOrigin: true,
          bypass(req, res, options) {
            const proxyURL = options.target + req.url
            // 将真实请求地址设置到响应头中
	          res.setHeader('x-req-proxyURL', proxyURL) 
          },
          // rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
        '/#': resolve(__dirname, 'src/types'),
        '@hs-ui-component': resolve(__dirname, '../components'),
      }
    },
    build: {
      rollupOptions: {
        external: /^src\/mock/  // 打包配置优化
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import "@/style.scss";',
        },
      },
    },
    // base: env.VITE_PACK_PATH // 配置打包路径
  }
})
